package com.example.capsule_netty.utils;


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author: zhuzhiming
 * @Date: 2022/4/27 20:39
 */
public class SpringUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (SpringUtils.applicationContext == null) {
            SpringUtils.applicationContext = applicationContext;
        }
    }

    private static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static Object getBeanByName(String beanName) {
        return applicationContext.getBean(beanName);
    }

//    public static Object getBeanByClass(Class<T> beanClass) {
//        return applicationContext.getBean(beanClass);
//    }

}
